package com.dawnClass.controller;

import com.dawnClass.pojo.Consumer;
import com.dawnClass.service.MycourseService;
import com.dawnClass.util.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class MyCourseController {
    @Autowired
    private MycourseService mycourseService;

    //加载个人课程数据,个人信息
    @GetMapping("mycourse")
    @ResponseBody
    public ModelAndView index(HttpSession session){
        //获取session中存储的consumer
        ServiceResponse consumerResponse = (ServiceResponse)session.getAttribute("ServiceResponse");
        Consumer consumer = (Consumer) consumerResponse.getdata();

        //通过用户id查询用户课程
        ServiceResponse serviceResponse1 = mycourseService.getById(consumer.getConsumerId());

        ModelAndView mav = new ModelAndView();

        mav.addObject("serviceResponse1",serviceResponse1);

        mav.setViewName("user/mycourse");
        return mav;
    }


}
